<?php
class Page_auth extends V_View {
        function index () {
        	V_Auth::authUser(); 
            // Получение количества листов
    		$wl_count=V_DB::count('v_work_list');
    		// Получение счетчика
    		$cmp_count=V_DB::fetch('SELECT page_text,id FROM v_system_pages WHERE page_name="comp_count"');
    		if (!empty($cmp_count)) {
    			$comp_count=$cmp_count['page_text']; 
    			$comp_count_id=$cmp_count['id']; 
    		}
    		else $comp_count='543789';
    		// Получение даты обновления счетчика
    		$date=V_DB::fetch('SELECT page_text, id FROM v_system_pages WHERE page_name="counter"');
    		if (!empty($date)) {  
    			$comp_date=$date['page_text'];
    			if ($comp_count>0) {
    				$comp_count+=round((time()-$comp_date)/2);
    				V_DB::updateArray('v_system_pages',$date['id'],Array (
    					Array ('name' => 'page_text','value' => '"'.time().'"')
    				));
    				V_DB::updateArray('v_system_pages',$comp_count_id,Array (
    					Array ('name' => 'page_text','value' => '"'.$comp_count.'"')
    				));
    			}
    		} else 
    			V_DB::insertArray('v_system_pages',Array (
    				Array ('name' => 'page_name','value' => '"counter"'),
    				Array ('name' => 'page_text','value' => '"'.time().'"')
    			));
    		
            $this->assign ('wl_count',$wl_count);
            $this->assign ('comp_count',$comp_count);
            $this->display('header-light.tpl');
            $this->display('pages/auth/index.tpl');
            $this->display('footer-light.tpl');
        }
        function logout () {
            session_destroy();
            V_Router::setPage('index');
        }
    }